home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0045_CRT Replacement Unit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  5.1 KB  |  324 lines

  1. unit mycrt;
  2. {$g+}
  3.  
  4. INTERFACE
  5.  
  6. const
  7.   colseg:word=$b800;
  8.  
  9. procedure ch2scr(x,y:word;ch:char;c:byte);
  10. procedure str2scr(const s:string;const x,y:word;const c:byte);
  11. function  readkey:char;
  12. function  keypressed:boolean;
  13. procedure centerstr(const s:string;const y:word;const c:byte);
  14. procedure centerstr2(const s:string;const y:word;const c:byte);
  15. procedure textbox(const x,y,x2,y2:byte;const c:byte;const cha:char);
  16. procedure clrscr(const where:word;const c:byte;const c2:char);
  17. function  activepage:byte;
  18. function  where_x(const page:byte):byte;
  19. function  where_y(const page:byte):byte;
  20. function  wherex:byte;
  21. function  wherey:byte;
  22. procedure goto_xy(const page,x,y:byte);
  23. procedure gotoxy(const x,y:byte);
  24. procedure setcursor(const cursor:word);
  25. function  getcursor:word;
  26. procedure hcursor;
  27. procedure scursor;
  28. procedure dupeit(c:char;co:byte;n,x,y:word);
  29. procedure statbar(snum,bnum:longint;x,y,fc,ec:byte);
  30.  
  31. IMPLEMENTATION
  32.  
  33. procedure ch2scr(x,y:word;ch:char;c:byte); assembler;
  34. asm
  35.   mov es,segb800
  36.   dec [x]
  37.   dec [y]
  38.   mov di,[y]
  39.   mov bx,di
  40.   shl di,6
  41.   shl bx,4
  42.   add di,bx
  43.   add di,[x]
  44.   mov al,[&ch]
  45.   mov ah,[c]
  46.   mov es:[di],ax
  47. end;
  48.  
  49. procedure str2scr(const s:string;const x,y:word;const c:byte); assembler;
  50. asm
  51.   push ds
  52.   dec [x]
  53.   dec [y]
  54.   mov es,segb800
  55.   mov di,[y]
  56.   mov bx,di
  57.   shl di,6
  58.   shl bx,4
  59.   add di,bx
  60.   add di,[x]
  61.   shl di,1
  62.   lds si,s
  63.  
  64.   xor ch,ch
  65.   mov cl,ds:[si]
  66.   inc si
  67.   mov ah,[c]
  68.  @@loop:
  69.    lodsb
  70.    stosw
  71.    loop @@loop
  72.  @@exit:
  73.  pop ds
  74. end;
  75.  
  76. function readkey:char; assembler;
  77. asm
  78.   xor ah,ah
  79.   int 16h
  80. end;
  81.  
  82. function keypressed:boolean; assembler;
  83. asm
  84.   mov ah, 01h
  85.   int 16h
  86.   mov ax, 00h
  87.   jz @1
  88.   inc ax
  89.   @1:
  90. end;
  91.  
  92. procedure centerstr(const s:string;const y:word;const c:byte); assembler;
  93. asm
  94.   push ds
  95.   xor ax,ax
  96.   xor cx,cx
  97.   dec [y]
  98.   mov es,segb800
  99.   mov di,[y]
  100.   mov bx,di
  101.   shl di,6
  102.   shl bx,4
  103.   add di,bx
  104.   shl di,1
  105.   lds si,s
  106.   mov bx,40
  107.   mov al,ds:[si]
  108.   mov cl,al
  109.   sub bx,ax
  110.   add di,bx
  111.   add di,bx
  112.   inc si
  113.   mov ah,[c]
  114.  @@loop:
  115.    lodsb
  116.    stosw
  117.    loop @@loop
  118.  @@exit:
  119.  pop ds
  120. end;
  121.  
  122. procedure centerstr2(const s:string;const y:word;const c:byte); assembler;
  123. var tempy:word;
  124. asm
  125.   push ds
  126.   xor ax,ax
  127.   xor cx,cx
  128.   xor dx,dx
  129.   dec [y]
  130.   mov es,segb800
  131.   mov di,[y]
  132.   mov bx,di
  133.   shl di,6
  134.   shl bx,4
  135.   add di,bx
  136.   shl di,1
  137.   mov tempy,di
  138.   lds si,s
  139.   mov cl,ds:[si]
  140.   mov dl,cl
  141.   mov bx,tempy
  142.   add bx,159
  143.   inc si
  144.   mov ah,[c]
  145.   mov al,' '
  146.  @@loop1: { This loop makes the 'bar'. }
  147.    stosw
  148.    cmp di,bx
  149.    jbe @@loop1
  150.   mov di,tempy
  151.   mov bx,40
  152.   shr dl,1
  153.   sub bx,dx
  154.   shl bx,1
  155.   sub bx,2
  156.   add di,bx
  157.  @@loop2: { This loop draws the text. }
  158.    lodsb
  159.    stosw
  160.    loop @@loop2
  161.  @@exit:
  162.   pop ds
  163. end;
  164.  
  165. procedure textbox(const x,y,x2,y2:byte;const c:byte;const cha:char); assembler;
  166. {
  167.   bl=X counter.
  168.   bh=Y counter.
  169.   cl=X max.
  170.   ch=Y max.
  171. }
  172. asm
  173.   mov es,segb800
  174.   xor ax,ax
  175.   mov al,[y]
  176.   mov di,ax
  177.   dec di
  178.   mov bx,di
  179.   shl di,6
  180.   shl bx,4
  181.   add di,bx
  182.   xor ax,ax
  183.   mov al,[x]
  184.   add di,ax
  185.   dec di
  186.   shl di,1
  187.  
  188.   mov bl,[x]
  189.   mov bh,[y]
  190.   mov cl,[x2]
  191.   mov ch,[y2]
  192.  
  193.   @@vertloop:
  194.  
  195. end;
  196.  
  197. procedure clrscr(const where:word;const c:byte;const c2:char); assembler;
  198. asm
  199.   mov ax,[where]
  200.   mov es,ax
  201.   xor di,di
  202.   mov cx,8000
  203.   mov al,[c2]
  204.   mov ah,[c]
  205.   rep stosw
  206. { The next code is just to recenter the cursor at (0,0) }
  207.   mov ah,0Fh
  208.   int 010h
  209.   mov ah,02h
  210.   mov dl,0
  211.   mov dh,0
  212.   int 010h
  213. end;
  214.  
  215. function activepage:byte; assembler;
  216. asm
  217.   mov ah,0Fh
  218.   int 010h
  219.   mov al,bh
  220. end;
  221.  
  222. function where_x(const page:byte):byte; assembler;
  223. asm
  224.   mov ah,03h
  225.   mov bh,[page]
  226.   int 010h
  227.   mov al,dl
  228. end;
  229.  
  230. function where_y(const page:byte):byte; assembler;
  231. asm
  232.   mov ah,03h
  233.   mov bh,[page]
  234.   int 010h
  235.   mov al,dh
  236. end;
  237.  
  238. function wherex:byte;
  239. begin
  240.   wherex:=succ(where_x(activepage));
  241. end;
  242.  
  243. function wherey:byte;
  244. begin
  245.   wherey:=succ(where_y(activepage));
  246. end;
  247.  
  248. procedure goto_xy(const page,x,y:byte); assembler;
  249. asm
  250.   mov ah,02h
  251.   mov bh,[page]
  252.   mov dl,[x]
  253.   mov dh,[y]
  254.   int 010h
  255. end;
  256.  
  257. procedure gotoxy(const x,y:byte);
  258. begin
  259.   goto_xy(activepage,pred(x),pred(y));
  260. end;
  261.  
  262. procedure setcursor(const cursor:word); assembler;
  263. asm
  264.   mov ah,1
  265.   mov bh,0
  266.   mov cx,[cursor]
  267.   int 010h
  268. end;
  269.  
  270. function getcursor:word; assembler;
  271. asm
  272.   mov ah,3
  273.   mov bh,0
  274.   int 010h
  275.   mov ax,cx
  276. end;
  277.  
  278. procedure hcursor;
  279. begin
  280.   setcursor($2000);
  281. end;
  282.  
  283. procedure scursor;
  284. begin
  285.   setcursor($0607);
  286. end;
  287.  
  288. procedure dupeit(c:char;co:byte;n,x,y:word); assembler;
  289. asm
  290.   mov es,segb800
  291.   mov di,[y]
  292.   dec di
  293.   mov bx,di
  294.   shl di,6
  295.   shl bx,4
  296.   add di,bx
  297.   add di,[x]
  298.   dec di
  299.   shl di,1
  300.   mov ah,[co]
  301.   mov al,[c]
  302.   cld
  303.   mov cx,n
  304.   rep stosw
  305. end;
  306.  
  307. procedure statbar(snum,bnum:longint;x,y,fc,ec:byte);
  308. const
  309.   magic=2; { 100/magic(2) = 50 }
  310.   empty='▒'; { #177 }
  311.   full='█';  { #219 }
  312. var
  313.   p1,p2:word;
  314.   s:string;
  315. begin
  316.   p1:=round(snum/bnum*100/magic);
  317.   p2:=round(snum/bnum*100);
  318.   str(p2,s);
  319.   dupeit(empty,ec,{50}(100 div magic)-p1,x,y);
  320.   dupeit(full,fc,p1-1,x,y);
  321.   str2scr(s,(x+(p1+((100 div magic)-p1))),y,fc);
  322. end;
  323.  
  324. end.